package com.infore.common.utils;

/**
 * 业务库基类：每个dao层的实现类应该继承此类
 * 
  * @ClassName: BaseHqlDao
  * @author log
  * @date 2018年6月29日 上午11:37:55
  * @最后修改人 log
  * @最后修改时间 2018年6月29日 上午11:37:55
 */
public abstract class BaseSqlUtils {

	/**
	 *根据用户选择传入字段
	 * @Title: sqlQuery
	 * @author: zhou kang
	 * @date 2018年7月12日 下午4:15:57
	 * @最后修改人: zhoukang
	 * @最后修改时间：2018年7月12日 下午4:15:57
	 * @param tbList
	 * @throws
	 */
	public static String sqlQuery(String tbList){
		StringBuilder sql = new StringBuilder();
		String sqlMet = "";
		String arry[] = tbList.split(",");
		for (int i=0;i<arry.length;i++) {
			if ("XH".equals(arry[i])){
				sql.append("rownum \"XH\",");
			}else if ("ZBMC".equals(arry[i])){
				sql.append("tt.zbmc \"ZBMC\",");
			}else if ("ZBLY".equals(arry[i])){
				sql.append("tt.zbly  \"ZBLY\",");
			}else if ("DW".equals(arry[i])){
				sql.append("tt.dw \"DW\",");
			}else if ("ZTMC".equals(arry[i])){
				sql.append("tt.ztmc \"ZTMC\",");
			}else if ("YWYMC".equals(arry[i])){
				sql.append("tt.ywymc \"YWYMC\",");
			}else if ("JSGS".equals(arry[i])){
				sql.append("tt.jsgs \"JSGS\",");
			}else if ("ZBDYYSM".equals(arry[i])){
				sql.append("tt.zbdyysm \"ZBDYYSM\",");
			}else if ("BZ".equals(arry[i])){
				sql.append("tt.bz \"BZ\",");
			}else if ("SFYZZB".equals(arry[i])){
				sql.append("tt.sfyzzb \"SFYZZB\",");
			}else if ("JGJXKH".equals(arry[i])){
				sql.append("tt.jgjxkh \"JGJXKH\",");
			}else if ("ZFBC".equals(arry[i])){
				sql.append("tt.zfbc \"ZFBC\",");
			}else if ("SQJGPJ".equals(arry[i])){
				sql.append("tt.sqjgpj \"SQJGPJ\",");
			}else if ("XCZEHD".equals(arry[i])){
				sql.append("tt.xczehd \"XCZEHD\",");
			}else if ("GLYYFWJG".equals(arry[i])){
				sql.append("tt.glyyfwjg \"GLYYFWJG\"");
			}
			}
			String a = sql.substring(sql.lastIndexOf(","));
			if (a.equals(",")){
				sqlMet=sql.substring(0,sql.length()-1);
			}else {
				sqlMet = sql.toString();
			}

		return 	sqlMet;
	}

	/**
	 *根据用户选择传入字段
	 * @Title: sqlQueryZb
	 * @author: zhou kang
	 * @date 2018年7月12日 下午4:15:57
	 * @最后修改人: zhoukang
	 * @最后修改时间：2018年7月12日 下午4:15:57
	 * @param tbList
	 * @throws
	 */
	public static String sqlQueryZb(String tbList){
		StringBuilder sql = new StringBuilder();
		String sqlMet = "";
		sql.append("t1.zbbm,row_number() over(partition by t1.zbbm order by t1.zbbm desc) row_index,");
		String arry[] = tbList.split(",");
		for (int i=0;i<arry.length;i++) {
			if ("ZBMC".equals(arry[i])){
				sql.append("t1.zbmc,");
			}else if ("ZBLY".equals(arry[i])){
				sql.append("t1.zbly,");
			}else if ("DW".equals(arry[i])){
				sql.append("t1.dw,");
			}else if ("ZTMC".equals(arry[i])){
				sql.append("t3.ztmc,");
			}else if ("YWYMC".equals(arry[i])){
				sql.append("t4.ywymc,");
			}else if ("JSGS".equals(arry[i])){
				sql.append("t1.jsgs,");
			}else if ("ZBDYYSM".equals(arry[i])){
				sql.append("t1.zbdyysm,");
			}else if ("BZ".equals(arry[i])){
				sql.append("t1.bz,");
			}else if ("SFYZZB".equals(arry[i])){
				sql.append("t1.sfyzzb,");
			}else if ("JGJXKH".equals(arry[i])){
				sql.append("t1.jgjxkh,");
			}else if ("ZFBC".equals(arry[i])){
				sql.append("t1.zfbc,");
			}else if ("SQJGPJ".equals(arry[i])){
				sql.append("t1.sqjgpj,");
			}else if ("XCZEHD".equals(arry[i])){
				sql.append("t1.xczehd,");
			}else if ("GLYYFWJG".equals(arry[i])){
				sql.append("t1.glyyfwjg");
			}
		}
		String a = sql.substring(sql.lastIndexOf(","));
		if (a.equals(",")){
			sqlMet=sql.substring(0,sql.length()-1);
		}else {
			sqlMet = sql.toString();
		}
		return 	sqlMet;
	}

}
